package com.briup;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class TestDomJ {
    public static void main(String[] args) {
        System.out.println("Hello World!");

        TestDomJ testDomJ= new TestDomJ();
        String filePath = "src/main/java/com/briup/TestDomJ.java";
        File file = new File(FilePath);
        try{
            Document  document = testDomJ.parse(file);
        System.out.println("document="+document);
        //调用自定义方法，处理文档对象
        testDomJ.handle(document);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public Document parse(File file) throws DocumentExceptccion{
       SAXReader reader = new SAXReader();
       Document document = reader.read(file);
        return document;
    }
    //main方法中不放太多的业务代码，所以将这些代码提取出来
    public void handle(Document document){
        System.out.println("handle="+document);
        //获取节点列表
        List<Node> list  =document.selectNodes("//sge");
        list.forEach(node->{
            System.out.println(node.getName()+":"+node.getTest());
        });
    }

}
